package com.micklebes.presentation;

import com.google.appengine.api.datastore.KeyFactory;
import com.micklebes.entity.Storage;
import com.micklebes.service.IStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.logging.Logger;

/**
 * User: Catalin
 * Date: 8/8/11
 * Time: 12:58 AM
 */

@Controller
@RequestMapping("/storage")
public class StorageController {
    private static Logger logger = Logger.getLogger(StorageController.class.getName());

    @Autowired
    private IStorageService iStorageService;

    @RequestMapping(method = RequestMethod.GET, value = "/{key}")
    public void getByKey(@PathVariable(value = "key") String key, HttpServletResponse response) {
        Storage storage = iStorageService.getByKey(KeyFactory.stringToKey(key));
        //  write to stream
    }

    @RequestMapping(method = RequestMethod.POST, value = "new")
    public void createStorage(HttpServletRequest request, HttpServletResponse response) {
        //get storage from request
//        iStorageService.createOrUpdate();
    }

    @RequestMapping(method = RequestMethod.GET, value = "findAll")
    public void getAllStorage(HttpServletResponse response) {
        iStorageService.getAll();
    }
}
